package com.liner.list;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;

public class ListDemo {
    public static void main(String[] args){


      ArrayList<String> list1 = new ArrayList<>();
      list1.add("one");
      list1.add("two");
      list1.add("three");
      list1.add("four");
      list1.add("five");

      System.out.println("正序排序:" + list1);

      for (int i = 0; i < list1.size()/2; i++) {
        String s = list1.get(i);  //获取正序的位置元素
        //将正数位置添加到倒数位置
        s = list1.set(list1.size() -1 -i, s);
        list1.set(i,s);
      }


      System.out.println("逆序排序:" + list1);



      List<String> list = new ArrayList<>();
      //List<String> list = new LinkedList<>();
      list.add("one");
      list.add("two");
      list.add("three");
      list.add("four");
      list.add("five");

        System.out.println("list:" + list);


        String two = list.get(1);
        System.out.println(two);

        list.set(2, "str");

        String old = list.set(3, "hello");
        System.out.println("替换前的旧元素:"+ old);

        System.out.println(list.get(2));

        for (int i = 0; i < list.size(); i++) {
            System.out.print(list.get(i) + "\t");
        }

        System.out.println();
        for (String s : list) {
            System.out.print(s + "\t");
        }
        System.out.println();
        Iterator<String> iterator = list.iterator();
        while (iterator.hasNext()) {

            System.out.print(iterator.next() + "\t");
        }

        System.out.println();

        String remove = list.remove(2);
        System.out.println("返回要删除的元素:" + remove);
        System.out.println("list:" + list);

        list.add(3,"seven");
        System.out.println("list:" + list);

    }
}
